<template>
  <div class="login-page">
    <img src="../assets/login/logo.png" class="logo" alt="" />
    <img src="../assets/login/text.png" class="web-text" alt="" />
    <div class="form">
      <el-form :model="param" :rules="rules" ref="loginRef" label-width="0px">
        <div class="title">欢迎登录</div>
        <el-form-item prop="username">
          <el-input v-model="param.username" placeholder="用户名" size="large">
            <template #prepend>
              <el-button :icon="User"></el-button>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item prop="password" :style="{ marginBottom: '5px' }">
          <el-input
            type="password"
            placeholder="密码"
            v-model="param.password"
            @keyup.enter="submitForm(login)"
            size="large"
          >
            <template #prepend>
              <el-button :icon="Lock"></el-button>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item>
          <div class="forget">
            <el-checkbox v-model="param.type" label="记住密码" size="large" />
            <router-link to="" class="link">忘记密码</router-link>
          </div>
        </el-form-item>
        <div class="login-btn">
          <el-button
            type="primary"
            @click="submitForm()"
            class="btn"
            size="large"
            >登录</el-button
          >
        </div>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from "vue";
import { useRouter } from "vue-router";
import { ElMessage } from "element-plus";
import { Lock, User } from "@element-plus/icons-vue";
import imgurl from "../assets/img/login.png";
import logo from "../assets/img/logo.png";

const router = useRouter();
const param = reactive({
  username: "",
  password: "",
  type: true,
});

const rules = reactive({
  username: [
    {
      required: true,
      message: "请输入用户名",
      trigger: "blur",
    },
  ],
  password: [{ required: true, message: "请输入密码", trigger: "blur" }],
});
const loginRef = ref("");

function submitForm() {
  loginRef.value.validate((valid) => {
    if (valid) {
      if (param.username !== "admin" || param.password !== "adm123") {
        return ElMessage.error("用户名或密码不正确");
      }
      ElMessage.success("登录成功");
      router.push("/home");
    }
  });
}
</script>

<style lang="scss" scoped>
.login-page {
  height: 100vh;
  width: 100%;
  overflow: hidden;
  background: url("../assets/login/bg.png") no-repeat left #dbe1ed;
  background-size: auto 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  .logo {
    position: absolute;
    top: 20px;
    left: 35px;
    width: 200px;
  }
  .web-text {
    width: 160px;
    position: absolute;
    left: 14%;
    top: 20%;
  }
  .form {
    border-radius: 5px;
    background-color: #fff;
    padding: 30px;
    width: 340px;
    margin-left: 50%;
    box-shadow: 0 1px 10px rgba(0, 0, 0, 0.1);
    .title {
      font-size: 24px;
      font-weight: bold;
      padding-bottom: 32px;
    }
    .btn {
      width: 100%;
    }
    .forget {
      width: 100%;
      color: #999;
      display: flex;
      align-items: center;
      justify-content: space-between;
      .link {
        margin-left: auto;
        color: #999;
      }
    }
  }
}
</style>
